﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AssociationCorpGUI
{
    //Delegates:
    public delegate void TryUnlockEventHandler(object sender, UnlockAssociationEventArgs e);

    public partial class dlgTryUnlock : UserControl
    {
        //Variables:
        private string tryText = "";

        //Properties:
        public int TextboxWidth { get { return this.txtbInput.Width; } }

        //Constructors:
        public dlgTryUnlock()
        {
            InitializeComponent();
        }
        public dlgTryUnlock(int maxLength) : this()
        {
            this.txtbInput.MaxLength = maxLength;
        }

        //Events:
        public event TryUnlockEventHandler TryUnlock;
        protected virtual void OnTryUnlock(UnlockAssociationEventArgs e)
        {
            if (TryUnlock != null)
            {
                TryUnlock(this, e);
            }
        }

        //Methods:
        private void txtbInput_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter || e.KeyChar == (char)Keys.Return)
            {
                btnTryUnlock_Click(this, e);
            }
        }

        private void btnTryUnlock_Click(object sender, EventArgs e)
        {
            this.tryText = txtbInput.Text;
            OnTryUnlock(new UnlockAssociationEventArgs(this.tryText));
            this.Dispose();
        }
        private void btnCancelTryUnlock_Click(object sender, EventArgs e)
        {
            this.tryText = "";
            this.Dispose();
        }
    }
}
